const EXCELJS = require('exceljs');
const fs = require('fs')
const WORKBOOK = new EXCELJS.Workbook();


// 合作方式
const Cooperation = {
    '股权投资': 1,
    '技术转让': 2,
    '许可使用': 3,
    '合作开发': 4,
    '合作兴办新企业': 5,
    '其他': 6,
}

// 需求类型
const RequireType = {
    '关键技术研发': 1,
    '产品升级': 2,
    '技术改造': 3,
    '设备改进': 4,
    '技术交易': 5,
    '技术咨询': 6,
    '海外创新合作': 7,
    '科技金融': 8,
}

async function readExcel(filePath) {
    await WORKBOOK.xlsx.readFile(filePath);
    const SHEET = WORKBOOK.worksheets[0];
    let arr = []
    SHEET.eachRow((row, rowNumber) => {
        let obj = {
            "id": 'XQ'+new Date().getTime()+rowNumber,
            "title": row.getCell(1).text,
            "abs": row.getCell(10).text,
            "time": "2023-05-13",
            "time2": row.getCell(7).text,
            "price": Number(row.getCell(5).text) || 0,
            "req": RequireType[row.getCell(2).text],
            "coo": Cooperation[row.getCell(3).text],
            "r":  row.getCell(8).text,
            "p": row.getCell(9).text,
        }
        arr.push(obj)
    });
    let p = {
        require:arr
    }
    fs.writeFile('require.json', JSON.stringify(p), () => {
        console.log('write');
    })
}

readExcel('./require.xlsx');